/*
 * Copyright (c) 2014, Mentor Graphics Corporation
 * Copyright (c) 2015 Xilinx, Inc.
 * Copyright (c) 2016 Freescale Semiconductor, Inc.
 * Copyright 2016-2022 NXP
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 3. Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef RPMSG_DEFAULT_CONFIG_H_
#define RPMSG_DEFAULT_CONFIG_H_

#define RL_USE_CUSTOM_CONFIG            (1)

#if RL_USE_CUSTOM_CONFIG
#include "rpmsg_config.h"
#endif

//! @def RL_MS_PER_INTERVAL
//! 用于轮询的非阻塞API函数中的延迟(单位: 毫秒). 默认值为1.
#ifndef RL_MS_PER_INTERVAL
#define RL_MS_PER_INTERVAL                      (1)
#endif

//! @def RL_ALLOW_CUSTOM_SHMEM_CONFIG
//! 该选项允许定义自定义共享内存配置, 并从rpmsg_config.h替换共享内存相关的全局设置.
//! 当多个实例并行运行, 但需要不同的共享内存安排(vring大小和对齐, 缓冲区大小和计数)时,
//! 该选项很有用.
//! 注意, 一旦启用了platform_get_custom_shmem_config()函数, 就需要在平台层实现.
//! 默认值为0 (所有RPMsg_Lite实例使用由公共配置宏定义的相同共享内存安排).
#ifndef RL_ALLOW_CUSTOM_SHMEM_CONFIG
#define RL_ALLOW_CUSTOM_SHMEM_CONFIG            (0)
#endif

#if !(defined(RL_ALLOW_CUSTOM_SHMEM_CONFIG) && (RL_ALLOW_CUSTOM_SHMEM_CONFIG == 1))
//! @def RL_BUFFER_PAYLOAD_SIZE
//! 缓冲区有效载荷大小, 它必须等于(240, 496, 1008, ...) [2^n - 16]。
//! 确保在rpmsg通信的两端定义了相同的值. 默认值为496.
#ifndef RL_BUFFER_PAYLOAD_SIZE
#define RL_BUFFER_PAYLOAD_SIZE                  (496U)
#endif

//! @def RL_BUFFER_COUNT
//! 缓冲区的数量, 它必须是2的幂(2, 4, ...) 默认值为2.
//! 注意, 这个值仅为rpmsg通信的一个方向定义了缓冲区计数.
//! 即, 如果主端和远端rpmsg_config.h文件中使用默认值2, 则在共享内存中总共创建了4个缓冲区.
#ifndef RL_BUFFER_COUNT
#define RL_BUFFER_COUNT                         (2U)
#endif

#else
//! 当设置RL_ALLOW_CUSTOM_SHMEM_CONFIG时, 定义缓冲区有效载荷和每个不同链接ID
//! (rpmsg_lite实例)的计数. 参考rpmsg_platform.h获取使用的链接ID.
#ifndef RL_BUFFER_PAYLOAD_SIZE
#define RL_BUFFER_PAYLOAD_SIZE(link_id)         (496U)
#endif

#ifndef RL_BUFFER_COUNT
#define RL_BUFFER_COUNT(link_id) (((link_id) == 0U) ? 256U : 2U)
#endif
#endif /* !(defined(RL_ALLOW_CUSTOM_SHMEM_CONFIG) && (RL_ALLOW_CUSTOM_SHMEM_CONFIG == 1))*/

//! @def RL_API_HAS_ZEROCOPY
//! 启用/禁用API零拷贝功能. 默认值为1(启用).
#ifndef RL_API_HAS_ZEROCOPY
#define RL_API_HAS_ZEROCOPY                     (1)
#endif

//! @def RL_USE_STATIC_API
//! 启用/禁用静态API函数(没有动态分配). 默认值为0(禁用静态API).
#ifndef RL_USE_STATIC_API
#define RL_USE_STATIC_API                       (0)
#endif

//! @def RL_CLEAR_USED_BUFFERS
//! 启用/禁用在返回的空闲缓冲区池之前清除已使用的缓冲区. 默认值为0(禁用).
#ifndef RL_CLEAR_USED_BUFFERS
#define RL_CLEAR_USED_BUFFERS                   (0)
#endif

//! @def RL_USE_MCMGR_IPC_ISR_HANDLER
//! 当启用IPC中断由多核管理器(IPC中断路由器)管理时, 当禁用RPMsg-Lite自己管理IPC中断.
//! 默认值为0(不使用MCMGR IPC ISR处理程序).
#ifndef RL_USE_MCMGR_IPC_ISR_HANDLER
#define RL_USE_MCMGR_IPC_ISR_HANDLER            (0)
#endif

//! @def RL_USE_ENVIRONMENT_CONTEXT
//! 当启用时, 环境层使用它自己的上下文.
//! 主要为QNX端口添加, 但如果需要也可以使用. 默认值是0(没有上下文，节省一些RAM).
#ifndef RL_USE_ENVIRONMENT_CONTEXT
#define RL_USE_ENVIRONMENT_CONTEXT              (0)
#endif

//! @def RL_DEBUG_CHECK_BUFFERS
//! 当启用缓冲指针传递给rpmsg_lite_send_nocopy()和rpmsg_lite_release_rx_buffer()
//! 函数(由RL_API_HAS_ZEROCOPY配置启用)时, 将检查以避免传递无效的缓冲指针.
//! 默认值为0(禁用). RPMsg-Lite到Linux配置不使用.
#ifndef RL_DEBUG_CHECK_BUFFERS
#define RL_DEBUG_CHECK_BUFFERS                  (0)
#endif

//! @def RL_ALLOW_CONSUMED_BUFFERS_NOTIFICATION
//! 当启用时, 每次接收到的缓冲区被消耗并放入可用缓冲区队列时, 对端都会收到通知.
//! 在RPMsg-Lite到Linux配置中启用此选项, 以允许解除Linux阻塞发送的阻塞.
//! 默认值为0 (RPMsg-Lite到RPMsg-Lite通信).
#ifndef RL_ALLOW_CONSUMED_BUFFERS_NOTIFICATION
#define RL_ALLOW_CONSUMED_BUFFERS_NOTIFICATION  (0)
#endif

//! @def RL_HANG
//! 挂起断言函数的默认实现.
static inline void RL_HANG(void)
{
    /* 当使用自己的RL_ASSERT实现时, 在单元测试中无法到达RL_HANG. */
    for (;;) {}
}

//! @def RL_ASSERT
//! 断言实现.
#ifndef RL_ASSERT
#define RL_ASSERT_BOOL(b) \
    do { if (!(b)) { RL_HANG(); }} while (0 == 1)
#define RL_ASSERT(x) RL_ASSERT_BOOL((int32_t)(x) != 0)

#endif

#endif /* RPMSG_DEFAULT_CONFIG_H_ */
